/********************************Copyright (c)**********************************\
**
**                   (c) Copyright 2019, Main, China, Mrtutu.
**                           All Rights Reserved
**
**                                By Mrtutu
**                           Blog: www.mrtutu.cn
**
**----------------------------------文件信息------------------------------------
** @flie    : SLE4442.h
** @auther  : Mrtutu
** @date    : 2019-10-30
** @describe: 
**
**----------------------------------版本信息------------------------------------
** 版本代号: V0.1
** 版本说明: 初始版本
**
**------------------------------------------------------------------------------
\********************************End of Head************************************/
 
#ifndef __S_L_E4442_H_
#define __S_L_E4442_H_
#include "CH554.H"

#define  u8  UINT8




#define  SLE_SDA_IN()    {Port1Cfg(3,6);}
#define  SLE_SDA_OUT()   {Port1Cfg(3,6);}


#define CARD_SIZE   224  //卡容量(256-32)
#define SLE_RD_MRAM 0X30 //主存储器
#define SLE_WR_MRAM 0x38

#define SLE_RD_PRAM 0X34 //保护存储器
#define SLE_WR_PRAM 0X3C

#define SLE_RD_PSCR 0X31 //安全储器器
#define SLE_WR_PSCR 0X39

#define SLE_PSC_CHK 0X33 //校验安全代码



//此处为IC卡保护区00~03单元的值,用于识别卡,这四个字节是SLE4442的标识,
//如果  IC卡保护区00~03单元的值 不是这四个字节，表明该卡不是SLE4442卡
//或卡已损坏
#define SLE4442ID1   0xA2     
#define SLE4442ID2   0x13
#define SLE4442ID3   0x10
#define SLE4442ID4   0x91
#define SLE4442      0x77     
#define SLE4428      0x78 


void SLE4442_Init(void);
void SLE4442_Delay(void);
void SLE4442_Start(void);
void SLE4442_Stop(void);
void SLE4442_Rst(void);
void SLE_Get_atr(u8 *buf);
void SLE_WR_Byte(u8 x);
u8 SLE_RD_Byte(void);
u8 SLE_Wait(void);
void SLE_Break(void);
void SLE_WR_Cmd(u8 cmd,u8 addr,u8 dat);
void SLE_RD_Data(u8 area, u8 addr, u8 len, u8*buf);
u8 SLE_Write(u8 area,u8 addr,u8 len,u8 *buf);
u8 SLE_Ver_Psc(u8 *psc);
unsigned char SLE_RD_CM(unsigned char StarAddr, unsigned char ByteNum, unsigned char* RecBuf);
unsigned char SLE_Check_PSW(unsigned char * psw);
unsigned char SLE_WR_PM(unsigned char StartAdr, unsigned char ByteNum, unsigned char* WriteBuf);
unsigned char SLE_WR_CM(unsigned char StarAddr, unsigned char ByteNum, unsigned char* WriteBuf);


#endif

/********************************End of File************************************/